package com.wjw.java.games.tankgame4;

import java.util.Vector;

/**
 * 我自己的坦克：英雄坦克
 */
public class HeroTank extends Tank {

    //子弹线程,单发
    private Shot shot = null;

    //子弹线程,多发
    Vector<Shot> shots = new Vector<>();

    //射击敌人坦克
    public void shotEnemyTank(){
        //只允许发射5发子弹
        /*if(shots.size() == 5){
            return;
        }*/

        int direction = getDirection();//获取方向,定义在Tank类中
        int x = getX();//x坐标
        int y = getY();//y坐标

        //根据方向创建Shot,即根据方向确定炮筒最前面的x,y坐标
        switch (direction){
            case 0://上
                shot = new Shot(x+20,y,0);
                break;
            case 1://右
                shot = new Shot(x+60,y+20,1);
                break;
            case 2://下
                shot = new Shot(x+20,y+60,2);
                break;
            case 3://左
                shot = new Shot(x,y+20,3);
                break;
        }
        shots.add(shot);//子弹加入到集合中

        Thread thread = new Thread(shot,"计算子弹坐标x,y线程：");
        thread.start();//启动,射击敌人坦克线程
    }

    //getter、setter、构造器...
    public Shot getShot() {
        return this.shot;
    }

    public void setShot(Shot shot) {
        this.shot = shot;
    }

    public Vector<Shot> getShots() {
        return this.shots;
    }

    public void setShots(Vector<Shot> shots) {
        this.shots = shots;
    }

    public HeroTank(int x, int y) {
        super(x, y);
        System.out.println("初始化HeroTank我自己的坦克...");
    }

}
